package demo.IOInputOutput;

import java.io.*;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/12-08-12-11:00
 * @Description：demo.IOInputOutput   文件流
 */
public class File_Stream {
    public static void main(String[] args) {
        File file = new File("D:\\qq文件\\jjy.jpg");
        //如果指定文件不存在，将会自动创建
        File targetFile = new File("hello.jpg");
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            //输入流
            in = new FileInputStream(file);

            //输出流
            out = new FileOutputStream(targetFile);

            int len = -1;
            byte[] b = new byte[1024];
            while((len = in.read(b))!= -1){
                out.write(b,0,len);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
